package cc.catface.api.business.app;

import cc.catface.common.output.ResultBody;
import cc.catface.dao.app.dto.LoginInDTO;
import cc.catface.dao.app.pojo.ApUser;
import cc.catface.service.app.ApUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/app/v1/user")
@Api(tags = "[移动]用户信息")
public class ApUserController {
    @Autowired
    private ApUserService userService;

    /**
     * 注册
     */
    @ApiOperation(value = "新增用户")
    @PostMapping("add")
    ResultBody add(@RequestBody ApUser user) {
        return userService.add(user);
    }

    @ApiOperation(value = "更新用户(根据id)")
    @PostMapping("update")
    ResultBody update(@RequestBody ApUser user) {
        return userService.update(user);
    }

    @ApiOperation(value = "查询用户(根据phone)")
    @GetMapping("get")
    ResultBody get(String phone) {
        return userService.get(phone);
    }

    @ApiOperation(value = "查询所有用户")
    @GetMapping("list")
    public ResultBody list() {
        return userService.list();
    }

    /**===*/
    @ApiOperation(value = "登录")
    @PostMapping("login")
    ResultBody login(@RequestBody LoginInDTO in) {
        return userService.login(in);
    }
}
